import request from "@/utils/request"
import type {
  /** 登录 */
  loginFormData,
  loginResponseData,
  pwdData,
  checkPwdResponseData,
  /** 用户界面 */
  userAllResponseData,
  userListResponseData,
  userListFormData,
  userInfoData
} from "./type"

// 枚举类型(添加=后，起到一个别名的作用)
enum API {
  /** 登录 */
  LOGIN_URL="/login",
  LOGOUT_URL="/logout",
  CHECK_PWD_URL = "/manage/user/pwd",
  UPDATE_PWD_URL = "/manage/user/pwd",
  /** 用户项 */
  USER_ALL_URL = "/manage/user/all",  //所有项
  USER_LIST_URL = "/manage/user/list",  //筛选项
  USER_ADD_URL = "/manage/user/add",  //添加项
  USER_GET_ID_URL="/manage/user/find", //获取id
  USER_UPDATE_URL="/manage/user/update", //修改
  USER_DELETE_URL= "/manage/user/delete"
}
/** 登录 */
// post请求：登录
export const reqLogin = (data:loginFormData)=>
  request.post<any,loginResponseData>(API.LOGIN_URL,data)
// post请求：登出
export const reqLogout = ()=>
  request.post<any,any>(API.LOGOUT_URL)
// post请求：密码验证
export const reqCheckPwd = (data:pwdData)=>
  request.post<any,checkPwdResponseData>(API.CHECK_PWD_URL,data)
// put请求：密码变更
export const reqUpdatePwd = (data:pwdData)=>
  request.put<any,checkPwdResponseData>(API.UPDATE_PWD_URL,data)

/** 用户区 */
// 读所有
export const reqUserAll = ()=>
  request.get<any,userAllResponseData>(API.USER_ALL_URL)
// 读筛选项
export const reqUserList = (data:userListFormData)=>
  request.post<any,userListResponseData>(API.USER_LIST_URL,data)
// 添加用户
export const reqUserAdd = (data:userInfoData)=>
  request.post<any,userListResponseData>(API.USER_ADD_URL,data)

//修改
export const reqUserById = (_id:string)=>
  request.get<any,loginResponseData>(API.USER_GET_ID_URL+`?_id=${_id}`)
export const reqUserUpdata = (data:userInfoData)=>
  request.post<any,loginResponseData>(API.USER_UPDATE_URL,data)
// 删除
export const reqUserDelete = (userId:string)=>
  request.post<any,loginResponseData>(API.USER_DELETE_URL,{userId})